Skip to content

Conversation

@mu001999
Copy link
Contributor

@mu001999 mu001999 commented Feb 5, 2026

Fixes #44232
Fixes #151752

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 5, 2026
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is neat! in the future, it would be easier to review if you split the rename into a separate commit from the change in behavior.

could you add some tests for this please?

View changes since this review

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from cb9b84c to cd83e12 Compare February 5, 2026 15:31
@mu001999
Copy link
Contributor Author

mu001999 commented Feb 5, 2026

Initial implementation completed. I plan to add more tests and check whether features in rustc are reported as unused correctly or not.

@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from cd83e12 to 2945856 Compare February 6, 2026 00:38
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2945856 to 36c0a20 Compare February 6, 2026 01:00
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 36c0a20 to 2ddaf82 Compare February 7, 2026 01:16
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2ddaf82 to fb08c95 Compare February 7, 2026 11:37
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from fb08c95 to 38aefe4 Compare February 7, 2026 12:45
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 38aefe4 to 0cda8d4 Compare February 7, 2026 13:35
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 0cda8d4 to 2d2577f Compare February 7, 2026 14:19
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 2d2577f to b67632e Compare February 7, 2026 15:08
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from a940d65 to 435090a Compare February 8, 2026 02:11
@mu001999
Copy link
Contributor Author

mu001999 commented Feb 11, 2026

Nice, CI has passes (finally :)), although I allowed unused_features somewhere (I try to only allow when there are complex platform-specific features enabled). But I think the next could be to merge the removal of unused features separately.

@rust-bors

This comment has been minimized.

}

static USED_FEATURES: LazyLock<Mutex<FxHashSet<Symbol>>> =
LazyLock::new(|| Mutex::new(FxHashSet::default()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this in the Session instead to correctly handle multiple compiler sessions in the same process?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also how are you ensuring that it works correctly with incr comp? Something needs to either record the side effects of marking a feature as used or force the query that marks a feature as used to be rerun.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this in the Session instead to correctly handle multiple compiler sessions in the same process?

Done. Thanks for the advice!

Copy link
Contributor Author

@mu001999 mu001999 Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also how are you ensuring that it works correctly with incr comp?

The query tracked_features_query is marked as eval_always and no_hash (as you suggested in the deleted comment, I thought wrongly that just the eval_always could make the node always red), so that any other queries depend on it (tcx.features() in fact) will re-compute. And then, checking the features is enabled or not will mark it as used in this table.

And TrackedFeatures does not implement HashStable, queries that depend on it can only check the feature internally but cannot pass or return TrackedFeatures to cause a unexpected usage outside query system. Therefore, as long as no other parts of the code directly use TrackedFeatures, it should work correctly with incremental compilation.

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from 84b5565 to c189c97 Compare February 12, 2026 14:46
@rust-log-analyzer

This comment has been minimized.

self.enabled_lang_features().hash_stable(hcx, hasher);
self.enabled_lib_features().hash_stable(hcx, hasher);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still necessary with the no_hash?

Copy link
Contributor Author

@mu001999 mu001999 Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed in the third commit. Let me squash these two commits.

@mu001999 mu001999 force-pushed the lint/unused_features branch 2 times, most recently from 4ba23c6 to acb3115 Compare February 12, 2026 15:16
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from acb3115 to 1875ae8 Compare February 12, 2026 15:50
@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 1875ae8 to 382a5fe Compare February 12, 2026 16:46
@rust-log-analyzer

This comment has been minimized.

@mu001999
Copy link
Contributor Author

mu001999 commented Feb 12, 2026

Some incremental tests failed because query features will be always dirty. And some of these have expired with current implementation. For now, I just update them to fit the new result directly. Expired ones should be removed if current implementation is accepted finally.

@rust-log-analyzer

This comment has been minimized.

@mu001999 mu001999 force-pushed the lint/unused_features branch from 5551df6 to b807143 Compare February 13, 2026 01:24
@mu001999 mu001999 force-pushed the lint/unused_features branch from b807143 to 9b6aa0d Compare February 13, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc could warn if a feature is unused Re-enable detection of unused library #![feature] directives

6 participants